<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="Bookmark" href="favicon.ico" >
	<link rel="Shortcut Icon" href="favicon.ico" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="/public/lib/html5.js"></script>
	<script type="text/javascript" src="/public/lib/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="/public/lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/css/style.css" />
	<!--[if IE 6]>
	<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<title>新建网站角色 - 管理员管理</title>
	<meta name="keywords" content="洛阳易购商城">
	<meta name="description" content="洛阳易购商城">
</head>
<body>
<article class="cl pd-20">
	<form action="" method="post" class="form form-horizontal" id="">
		<input type="hidden" value="{$supplier_id}" id="supplier_id">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>供货商名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['supplier_name']}" placeholder="供货商名称" class="input-text" id="supplier_name" name="supplier_name">
				<p class="error">请输入供货商名称</p>
				<p class="error">供货商名称不合法</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>联系人姓名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['name']}" placeholder="联系人姓名" class="input-text" id="name" name="name">
				<p class="error">请输入联系人姓名</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>联系人电话：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['tel']}" class="input-text" placeholder="联系人电话" id="tel">
				<p class="error">请输入联系人电话</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>联系人地址：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['address']}" class="input-text" placeholder="联系人地址" id="address">
				<p class="error">请输入联系人地址</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">供货商图片：</label>
			<div class="formControls col-xs-8 col-sm-9">
					<p style="height: 165px;width:165px;border: dashed 1px #e5e5e5">
						{if $info['logo']==''}
						<img src="" alt="" id="imgbrand_pic" class="thumbnail">
						{else}
						<img src="/{$info['logo']}" alt="" id="imgbrand_pic" class="thumbnail">
						{/if}
					</p>
				<div class="upload-btn">
				<span>
					<input name="file_upload" style="display: none" id="uploadImg" type="file" onchange="imgUpload(this);">
					<input type="hidden" value="{$info['logo']}" id="brand_pic" />
				</span>
					<input class="btn radius btn-secondary" onclick="on_upload()" type="button" value="上传图片">
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">备注：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="" cols="" rows="" id="info" class="textarea"  placeholder="说点什么...100个字符以内" dragonfly="true" onKeyUp="textarealength(this,100)">{$info['info']}</textarea>
				<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" onclick="addSuppAjax()" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
<script type="text/javascript" src="/public/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/public/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/public/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="/public/static/h-ui.admin/js/H-ui.admin.page.js"></script>
<script type="text/javascript" src="/public/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/public/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/public/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script src="/public/static/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="/public/static/js/file_upload.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
});
function on_upload() {
	$("#uploadImg").click();
}
//模块输入信息验证
function verify() {
    var supplier_name = $("#supplier_name").val();
    var name = $("#name").val();
    var tel = $("#tel").val();
    var address = $("#address").val();
    var info = $("#info").val();
    if (supplier_name == '') {
        $("#supplier_name").next().show();
        return false;
    } else {
        $(".error").hide();
    }
    pattern= new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？_]");
    if(pattern.test(supplier_name)){
        $("#supplier_name").next().next().show();
        return false;
    }
    if (name == '') {
        $("#name").next().show();
        return false;
    } else {
        $(".error").hide();
    }
    if(tel == ''){
        $("#tel").next().show();
        return false;
    }else{
        $(".error").hide();
    }
    if(address == ''){
        $("#address").next().show();
        return false;
    }else{
        $(".error").hide();
    }
    return true;
}
var flag = false;//防止重复提交
//添加用户
function addSuppAjax() {
    var supplier_id = $("#supplier_id").val();
    var supplier_name = $("#supplier_name").val();
    var name = $("#name").val();
    var tel = $("#tel").val();
    var address = $("#address").val();
    var info = $("#info").val();
    var logo=$("#brand_pic").val();
    if(verify() && !flag){
        flag = true;
        $.ajax({
            type : "post",
            url : "{:url('goods/supplier_edit')}",
            data : {
                'supplier_id':supplier_id,
                'supplier_name' : supplier_name,
                'name' : name,
                'tel' : tel,
                'address' : address,
				'info':info,
				'logo':logo
            },
            success : function(data) {
                if(data['code']>0){
                    layer.msg('修改成功!',{icon:1,time:1000},function () {
                        window.parent.location.href="{:url('goods/supplier')}";
                    });
                }
                else{
                    flag = false;
                    layer.msg(data['message'],{icon:5,time:1000});
                }
            }
        });
    }
}
//供货商图片上传
function imgUpload(event) {
    var fileid = $(event).attr("id");
    var str = $(event).next().attr("id");
    var data = { 'file_path' : "supp/" };
    uploadFile(fileid,data,function(res){
        if(res.code){
            $("#img"+str).attr("src",res.data);
            $("#"+str).val(res.data);
            layer.msg(res.message,{icon:1,time:1000});
        }else{
            layer.msg(res.message,{icon:1,time:1000});
        }
    });
}
</script>
</body>
</html>